/*
 * Write a program to sort a stack in ascending order. You should not make any assumptions 
 * about how the stack is implemented. The following the only functions that should be used 
 * to write this program: push|pop|peek|isEmpty.
 */
package Chapter3;

public class Chapter3_6 {
	public MyStack stackSort(MyStack stack)
	{
		MyStack sortedStack = new MyStack();
		int item;
		while(!stack.isEmpty())
		{
			item = stack.pop().value;
			while(!sortedStack.isEmpty() && sortedStack.peek().value > item)
			{
				stack.push(sortedStack.pop().value);
			}
			sortedStack.push(item);
		}
		return sortedStack;
	}
	
//	public static void main(String args[])
//	{
//		MyStack stack = new MyStack();
//		stack.push(35);
//		stack.push(58);
//		stack.push(13);
//		stack.push(19);
//		stack.push(88);
//		Chapter3_6 test = new Chapter3_6();
//		MyStack sortedStack = test.stackSort(stack);
//		sortedStack.checkStackResult();
//	}

}
